/*
//	CP2013 Traffic Simulator Assignment :: (MVC) View (Function Definitions)
//	Copyright (c) 2010, Adam Rehn
//
//	This file contains the function definitions for this component.
*/
#include "view.h"

//Contructor and Destructor
mvcView::mvcView()
{
	//Set the visualisation window pointer to null
	vis = NULL;
}

mvcView::~mvcView()
{
	cout << "Destroying vis window in destructor...\n";
	//system("pause");
	if (vis) delete vis;
}

//Use this to set the cycle length in seconds
void  mvcView::setCycleLength(double cycleLength)
{
	//Don't bother doing anything unless the visualisation window is open
	if (vis)
	{
		//Set the cycle length
		vis->setCycleLength(cycleLength);
	}
}

//Use this to composite the map
void mvcView::resetView(mvcModel* model)
{
	//Create a new visualisation if it does not already exist
	if (!vis)
		vis = new visualisationWindow(model->overallSimulationArea.w, model->overallSimulationArea.h);
	else
	{
		//If the window is already open, resize it accordingly
		vis->setWindowSize(model->overallSimulationArea.w, model->overallSimulationArea.h);
	}
	
	cout << "Compositing map...\n";
	vis->compositeMap(model);
	
	cout << "Rendering initial...\n";
	vis->renderToScreen();
}

//Use this to update the dynamic layers
void mvcView::updateView(mvcModel* model, clock_t start, unsigned int i, unsigned int t)
{
	//Don't bother doing anything unless the visualisation window is open
	if (vis)
	{
		//Update the dynamic layers and render to the screen
		vis->updateCarsAndLights(model);
		vis->renderToScreen(start, i, t);
	}
}

//Use this to set the window title of the visualisation window
void mvcView::setVisWindowTitle(char* title)
{
	vis->setWindowTitle(title);
}
